$(function(){
	
	$('#switch_qlogin').click(function(){
		$('#switch_login').removeClass("switch_btn_focus").addClass('switch_btn');
		$('#switch_qlogin').removeClass("switch_btn").addClass('switch_btn_focus');
		$('#switch_bottom').animate({left:'0px',width:'70px'});
		$('#qlogin').css('display','none');
		$('#web_qr_login').css('display','block');
		
		});
	$('#switch_login').click(function(){
		
		$('#switch_login').removeClass("switch_btn").addClass('switch_btn_focus');
		$('#switch_qlogin').removeClass("switch_btn_focus").addClass('switch_btn');
		$('#switch_bottom').animate({left:'154px',width:'70px'});
		
		$('#qlogin').css('display','block');
		$('#web_qr_login').css('display','none');
		});
if(getParam("a")=='0')
{
	$('#switch_login').trigger('click');
}

	});
	
function logintab(){
	scrollTo(0);
	$('#switch_qlogin').removeClass("switch_btn_focus").addClass('switch_btn');
	$('#switch_login').removeClass("switch_btn").addClass('switch_btn_focus');
	$('#switch_bottom').animate({left:'154px',width:'96px'});
	$('#qlogin').css('display','none');
	$('#web_qr_login').css('display','block');
	
}


//根据参数名获得该参数 pname等于想要的参数名 
function getParam(pname) { 
    var params = location.search.substr(1); // 获取参数 平且去掉？ 
    var ArrParam = params.split('&'); 
    if (ArrParam.length == 1) { 
        //只有一个参数的情况 
        return params.split('=')[1]; 
    } 
    else { 
         //多个参数参数的情况 
        for (var i = 0; i < ArrParam.length; i++) { 
            if (ArrParam[i].split('=')[0] == pname) { 
                return ArrParam[i].split('=')[1]; 
            } 
        } 
    } 
}  


var reMethod = "GET",
	pwdmin = 6;

$(document).ready(function() {
	$('#reg').click(function() {

		if ($('#user').val() == "") {
			$('#user').focus().css({
				border: "1px solid red",
				boxShadow: "0 0 2px red"
			});
			$('#userCue').html("<font color='red'><b>×用户名不能为空</b></font>");
			return false;
		}
		if ($('#user').val().length < 2 || $('#user').val().length > 10) {

			$('#user').focus().css({
				border: "1px solid red",
				boxShadow: "0 0 2px red"
			});
			$('#userCue').html("<font color='red'><b>×用户名位4-10字符</b></font>");
			return false;

		}
		var flag = false;
		$.ajax({
			type: "post",
			url: "UserAction_checkUserName",
			data: "name=" + $("#user").val(),
			dataType: 'json',
			async:false,
			success: function(result) {
               if(result=="1"){
            	   $('#userCue').html("<font color='red'><b>×用户名已存在</b></font>");
            	   flag = true;
               }
			}  
		});
		if(flag){
			return false;
		}
		if ($('#passwd').val().length < pwdmin) {
			$('#passwd').focus();
			$('#userCue').html("<font color='red'><b>×密码不能小于" + pwdmin + "位</b></font>");
			return false;
		}
		if ($('#passwd2').val() != $('#passwd').val()) {
			$('#passwd2').focus();
			$('#userCue').html("<font color='red'><b>×两次密码不一致！</b></font>");
			return false;
		}

		var sqq = /^1[3|4|5|8][0-9]\d{8}$/;
		if (!sqq.test($('#qq').val()) || $('#qq').val().length < 5 || $('#qq').val().length > 12) {
			$('#qq').focus().css({
				border: "1px solid red",
				boxShadow: "0 0 2px red"
			});
			$('#userCue').html("<font color='red'><b>×手机号码格式不正确</b></font>");
			return false;
		} else {
			$('#qq').css({
				border: "1px solid #D7D7D7",
				boxShadow: "none"
			});
		}
		$.ajax({
			type: "post",
			url: "UserAction_checkUserid",
			data: "userid="+$("#qq").val(),
			dataType: 'json',
			async:false,
			success: function(result) {
               if(result=="1"){
            	   $('#userCue').html("<font color='red'><b>×手机号码已存在</b></font>");
            	   flag = true;
               }
			}  
		});
		if(flag){
			return false;
		}
		$.ajax({
			type: "post",
			url: "UserAction_regUser",
			data: "name=" + $("#user").val()+"&password="+$("#passwd").val()+"&userid="+$("#qq").val(),
			dataType: 'json',
			async:false,
			success: function(result) {
               if(result=="1"){
            	   $('#userCue').html("<font color='red'><b>√注册成功</b></font>");
            	   setTimeout("location.href='index.html'",1000); 
               }else{
            	   $('#userCue').html("<font color='red'><b>×注册失败</b></font>"); 
               }
			}  
		});
		
	});
	$('#loginButton').click(function(){
		$.post("UserAction_login",{
			userid:$("#u").val(),
		    password:$("#p").val()
		},function(data){
			//var msg = JSON.parse(data);
			if(data=="1"){
				location.href="/manager/web/Default.html";
			}else{
				$("#loginMsg").html("<font color='red'>登录失败!检查用户名或密码</font>");
			}
		});
	});

});